﻿Imports System.Data
Imports System.Data.SqlClient
Public Class KiemTraNha_DAO
    Public Shared Function ThemXacNhan(ByVal KT As KiemTraNha_DTO) As Boolean
        Dim cn As SqlConnection = DataProvider.KetNoi()
        Dim check As Boolean = True
        Dim cm As SqlCommand = New SqlCommand("themKT", cn)
        cm.CommandType = CommandType.StoredProcedure

        cm.Parameters.AddWithValue("@MaQL", KT.MaQL)
        cm.Parameters.AddWithValue("@MaNha", KT.MaNha)
        cm.Parameters.AddWithValue("@NgayKT", KT.NgayKiemTra)
        cm.Parameters.AddWithValue("@TrangThai", KT.Trangthai)
        cm.Parameters.AddWithValue("@MaNguoiThue", KT.MaNguoiThue)
        Try
            cm.ExecuteNonQuery()

            cn.Close()
        Catch ex As Exception
            cn.Close()
            check = False

        End Try
        Return (check)
    End Function
    Public Shared Function LoadQLNha() As DataTable
        Dim cn As SqlConnection = DataProvider.KetNoi()
        Dim cm As SqlCommand = New SqlCommand("loadQLNha", cn)
        Dim tao As SqlDataAdapter = New SqlDataAdapter(cm)
        Dim bang As New DataTable
        tao.Fill(bang)
        Return bang
    End Function
    Public Shared Function UpdateQLNha(ByVal KT As KiemTraNha_DTO) As Boolean
        Dim cn As SqlConnection = DataProvider.KetNoi()
        Dim check As Boolean = True
        Dim cm As SqlCommand = New SqlCommand("updateKTnha", cn)
        cm.CommandType = CommandType.StoredProcedure
        'Dim id As Integer = TaoIDTuDong()
        cm.Parameters.AddWithValue("@stt", KT.MaThe)
        cm.Parameters.AddWithValue("@tenql", KT.TenQL)
        cm.Parameters.AddWithValue("@tennguoithue", KT.TenNguoiThue)
        cm.Parameters.AddWithValue("@ngay ", KT.NgayKiemTra)
        cm.Parameters.AddWithValue("@trangthai", KT.Trangthai)
        cm.Parameters.AddWithValue("@Tenguoichothue", KT.TenNguoiChoThue)

        Try
            cm.ExecuteNonQuery()

            cn.Close()
        Catch ex As Exception
            cn.Close()
            check = False

        End Try
        Return (check)
    End Function
    Public Shared Function XoaQuanLyNha(ByVal KT As String) As Boolean
        Dim cn As SqlConnection = DataProvider.KetNoi()
        Dim check As Boolean = True
        Dim cm As SqlCommand = New SqlCommand("xoaKTnha", cn)
        cm.CommandType = CommandType.StoredProcedure

        cm.Parameters.AddWithValue("@stt", KT)

        Try
            cm.ExecuteNonQuery()

            cn.Close()
        Catch ex As Exception
            cn.Close()
            check = False

        End Try
        Return (check)
    End Function
End Class
